﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls.Primitives;

namespace Kokomo.Controls
{
	public class DiagramItem : HeaderedContentControl
	{
		static DiagramItem()
		{
			DefaultStyleKeyProperty.OverrideMetadata(typeof(DiagramItem), new FrameworkPropertyMetadata(typeof(DiagramItem)));
			FocusableProperty.OverrideMetadata(typeof(DiagramItem), new FrameworkPropertyMetadata(false));
			//FocusManager.IsFocusScopeProperty.OverrideMetadata(typeof(DiagramItem), new FrameworkPropertyMetadata(true));
		}

		public DiagramItem()
		{
		}

		#region Layout
		internal Size SubbranchSize { get; set; }
		#endregion

		#region Resizing
		public bool Resizable
		{
			get { return (bool)GetValue(ResizableProperty); }
			set { SetValue(ResizableProperty, value); }
		}

		// Using a DependencyProperty as the backing store for Resizable.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty ResizableProperty = LayoutHandle.ResizableProperty.AddOwner(typeof(DiagramItem), new UIPropertyMetadata(true));

		#endregion

		#region Templating
		//public const string TopLeftPartName = "PART_TopLeft";
		//public const string TopPartName = "PART_Top";
		//public const string TopRightPartName = "PART_TopRight";
		//public const string LeftPartName = "PART_Left";
		//public const string RightPartName = "PART_Right";
		//public const string BottomLeftPartName = "PART_BottomLeft";
		//public const string BottomPartName = "PART_Bottom";
		//public const string BottomRightPartName = "PART_BottomRight";

		//public override void OnApplyTemplate()
		//{
		//    base.OnApplyTemplate();
		//}
		#endregion

		protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
		{
			base.OnIsKeyboardFocusWithinChanged(e);

			Selector parentSelector = ItemsControl.ItemsControlFromItemContainer(this) as Selector;
			if (parentSelector != null)
				parentSelector.SelectedItem = parentSelector.ItemContainerGenerator.ItemFromContainer(this);
		}

		#region Connectors


		public IEnumerable<Connector> Connectors
		{
			get { return (IEnumerable<Connector>)GetValue(ConnectorsProperty); }
			set { SetValue(ConnectorsProperty, value); }
		}

		// Using a DependencyProperty as the backing store for Connectors.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty ConnectorsProperty =
			DependencyProperty.Register("Connectors", typeof(IEnumerable<Connector>), typeof(DiagramItem), new UIPropertyMetadata(null));


		#endregion
	}
}
